<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{common::header('需求计划录入')}">
    <meta charset="utf-8">
</head>
<body style="overflow-x: hidden">
<div class="container-fluid">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <ul class="breadcrumb">
                <li class="active">
                    选择物资
                </li>
                <li>
                    <a>录入需求计划</a>
                </li>
                <li>
                    <a>需求计划确认</a>
                </li>
            </ul>
        </div>
    </div>
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <form id="fm" method="post">
                        <table style="min-height: 200px;overflow: hidden" id="dg1" class="easyui-datagrid"
                               data-options="
                                    rownumbers:true,
                                    method:'get',
                                    width:'100%'">
                            <thead>
                            <tr>
                                <th data-options="field:'ck',checkbox: true"></th>
                                <th data-options="field:'id'" hidden>Item ID(15%)</th>
                                <th data-options="field:'materialNum',width:'48%'">产品编码</th>
                                <th data-options="field:'materialName',width:'48%'">名称</th>
                            </tr>
                            </thead>
                        </table>
                    </form>
                </div>
            </div>
            <div class="row clearfix">
                <div class="col-md-12 column" style="padding-top:10px;text-align:right">
                    <button type="button" class="btn btn-primary" onclick="btn1()">下一步</button>
                </div>
            </div>
        </div>
    </div>


    <div class="row clearfix">
        <div class="col-md-12 column">
            <hr>
        </div>
        <div class="col-md-12 column">
            <div class="col-sm-4 col-md-3 column form-inline">
                <label for="a1">产品编码:</label>
                <input type="email" class="form-control" id="a1" placeholder="产品编码">
            </div>
            <div class="col-sm-4 col-md-3 column form-inline">
                <label for="a2">产品名称:</label>
                <input type="email" class="form-control" id="a2" placeholder="产品名称">
            </div>
            <div class="col-sm-4 col-md-3 column form-inline">
                <label for="a3">产品类型:</label>
                <input type="email" class="form-control" id="a3" placeholder="产品类型">
            </div>
            <div class="col-sm-12 col-md-3 column" >
                <button type="button" class="btn btn-primary" onclick="btn2()" style="float: left">搜索</button>
                <button type="button" class="btn btn-primary" onclick="btn3()" style="float: left;margin-left: 10px">重置</button>
                <button type="button" class="btn btn-primary" onclick="btn4()" style="float: right">更多</button>
            </div>

        </div>
    </div>



    <div class="row clearfix" style="padding-top:10px ">
        <div class="row clearfix">
            <div class="col-md-12 column">
                <div class="col-md-12 column" style="overflow: hidden">
                    <table id="dg" class="easyui-datagrid"
                           data-options="
								  	pageSize:'5',
								  	pageList:[5,10,20,30,40,50],
									rownumbers:true,
									pagination:true,
									url:'/material/findMaterialPage',
									method:'get',
									width:'100%'">
                        <thead>
                        <tr>
                            <th data-options="field:'ck',checkbox: true">Item ID(15%)</th>
                            <th data-options="field:'id'" hidden>Item ID(15%)</th>
                            <th data-options="field:'materialNum',width:'48%'">物资编码</th>
                            <th data-options="field:'materialName',width:'48%'">物资名称</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>

            <div class="col-md-12 column">
                <div class="col-md-12 column" style="padding-top:10px;text-align:right">
                    <button type="button" onclick="bnt5()"  class="btn btn-primary" >添加</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    //添加数据
    function bnt5(){
        bnt10($('#dg').datagrid('getSelections'));
    }

    //打开物资信息
    var btn4=function(){
        window.open("wangyeduihakuang.html","Son","");
    }
    //清空搜索
    var btn3=function(){
        $("#a1").val("");
        $("#a2").val("");
        $("#a3").val("");
    }

    //模糊查询
    var btn2=function (){
        var a1=$("#a1").val();
        var a2=$("#a2").val();
        var a3=$("#a3").val();
        $('#dg').datagrid({
            url:'/material/findMaterialPage',
            method:'get',
            queryParams: {
                MaterialName:a2,
                MaterialType:a3,
                MaterialNum:a1
            }
        });
    }

    //下一步
    var btn1=function (){
        var rows=$('#dg1').datagrid('getSelections');
        if (rows.length!=0){
            var temp = document.createElement("form")
            temp.action = "/material/next";
            temp.method = "post";
            temp.style.display = "none";
            for(var i=0; i<rows.length; i++){
                var opt = document.createElement("input");
                opt.name = "nums";
                opt.value =rows[i].id;
                temp.appendChild(opt);
            }
            document.body.appendChild(temp);
            temp.submit();
        }else{
            alert("未选择");
        }
    }

    //转移数据
    var bnt10=function (data){
        for(var i=0; i<data.length; i++){
            $("#dg1").datagrid('appendRow',
                {id:data[i].id,
                materialNum:data[i].materialNum,
                materialName:data[i].materialName});
        }
    }








    // window.onscroll = function() {scrollFunction()};
    //
    // function scrollFunction() {console.log(121);
    // 	if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
    // 		document.getElementById("myBtn").style.display = "block";
    // 	} else {
    // 		document.getElementById("myBtn").style.display = "none";
    // 	}
    // }
    //
    // // 点击按钮，返回顶部
    // function topFunction() {
    // 	document.body.scrollTop = 0;
    // 	document.documentElement.scrollTop = 0;
    // }
</script>

</body>
</html>